package utils

import (
	"encoding/json"

	"boomlive.com/boomlive-common/configs"
	"boomlive.com/boomlive-common/constants"
	"github.com/beego/beego/v2/core/logs"
)

func SetLogConfig() {

	log := logs.GetBeeLogger()

	config := map[string]interface{}{
		"filename":    "logs/app.log",
		"maxdays":     180,
		"daily":       true,
		"rotate":      true,
		"maxlines":    100000,
		"maxsize":     50 * 1024 * 1024,
		"log_request": false,
		"RotatePerm":  "0664",
		"perm":        "0664",
	}

	jsonConf, err := json.Marshal(config)

	if err != nil {
		return
	}

	err = log.SetLogger(logs.AdapterFile, string(jsonConf))

	if err != nil {
		return
	}

	env := configs.EnvName

	if env == constants.ENV_DEV {
		log.SetLevel(logs.LevelDebug)
	} else if env == constants.ENV_DEBUG {
		log.SetLevel(logs.LevelDebug)
		_ = log.DelLogger(logs.AdapterConsole)
	} else {
		log.SetLevel(logs.LevelInfo)
		_ = log.DelLogger(logs.AdapterConsole)
	}

	log.EnableFuncCallDepth(true)

	return
}
